package com.gitee.sys.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gitee.mybase.top.entity.BaseDict;
import com.gitee.sys.service.IBaseDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chengkaimao
 * @since 2018-12-10
 */
@RestController
@RequestMapping("/sys/base-dict")
@Api("基础数据字典相关的api")
public class BaseDictController {

    @Reference
    private IBaseDictService baseDictService;


    @ApiOperation(value = "基础数据字典分页查询", notes = "基础数据字典分页查询", httpMethod = "GET")
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页", paramType = "query", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "size", value = "每页条数", paramType = "query", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "dictCode", value = "字典编码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dictName", value = "字典名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "dictType", value = "字典类型", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "scene", value = "字典场景", paramType = "query", dataType = "String")})
    @GetMapping("page")
    public ResponseEntity<IPage<BaseDict>> getPage(@RequestParam long current, @RequestParam long size, @ApiIgnore BaseDict baseDict){
        IPage<BaseDict> page = baseDictService.getPage(current, size, baseDict);
        return ResponseEntity.ok(page);
    }

    @PostMapping
    @ApiOperation(value = "新增基础数据字典", notes = "新增基础数据字典", httpMethod = "POST")
    public ResponseEntity<Void> saveBaseDict(@RequestBody BaseDict baseDict) {
        baseDictService.saveDict(baseDict);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @PutMapping
    @ApiOperation(value = "更新基础数据字典", notes = "更新基础数据字典", httpMethod = "PUT")
    public ResponseEntity<Void> updateBaseDict(@RequestBody BaseDict baseDict){
        baseDictService.updateDict(baseDict);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();

    }

    @DeleteMapping
    @ApiOperation(value = "删除基础数据字典", notes = "删除基础数据字典", httpMethod = "DELETE")
    public ResponseEntity<Void> deleteBaseDict(@RequestParam Long id){
        baseDictService.delDict(id);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

}
